Skip to content

Commit c3dbd41

Browse files
committed
feat: update black and format code to match Python 3.11
1. Update required version of `black` in `pyproject.toml` and `.circleci/config.yml`. 2. Update Python version identifiers in `tool.black` section of `pyproject.toml` to include `py311` and `py312`. 3. Modify invocation of `black` in `commands.py` to format with `py311`. 4. Regenerate and reformat code.
1 parent 51911a4 commit c3dbd41

37 files changed

+69
-26
lines changed

Diff for: .circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
command: |
130130
python -m venv venv
131131
. venv/bin/activate
132-
pip install black==22.3.0
132+
pip install black==25.1.0
133133
- run:
134134
name: Check formatting with black
135135
command: |

Diff for: _plotly_utils/colors/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
Be careful! If you have a lot of unique numbers in your color column you will
7474
end up with a colormap that is massive and may slow down graphing performance.
7575
"""
76+
7677
import decimal
7778
from numbers import Number
7879

Diff for: codegen/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
get_data_validator_instance,
2727
)
2828

29+
# Target Python version for code formatting with Black.
30+
# Must be one of the values listed in pyproject.toml.
31+
BLACK_TARGET_VERSION = "py311"
32+
2933

3034
# Import notes
3135
# ------------
@@ -326,9 +330,10 @@ def __getattr__(import_name):
326330

327331
# ### Run black code formatter on output directories ###
328332
if reformat:
329-
subprocess.call(["black", "--target-version=py36", validators_pkgdir])
330-
subprocess.call(["black", "--target-version=py36", graph_objs_pkgdir])
331-
subprocess.call(["black", "--target-version=py36", graph_objects_path])
333+
target_version = f"--target-version={BLACK_TARGET_VERSION}"
334+
subprocess.call(["black", target_version, validators_pkgdir])
335+
subprocess.call(["black", target_version, graph_objs_pkgdir])
336+
subprocess.call(["black", target_version, graph_objects_path])
332337
else:
333338
print("skipping reformatting")
334339

Diff for: commands.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
]
2323
)
2424

25+
2526
# Load plotly.js version from js/package.json
2627
def plotly_js_version():
2728
path = os.path.join(PROJECT_ROOT, "js", "package.json")

Diff for: plotly/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- exceptions: defines our custom exception classes
2626
2727
"""
28+
2829
import sys
2930
from typing import TYPE_CHECKING
3031
from _plotly_utils.importers import relative_import

Diff for: plotly/basedatatypes.py

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _make_underscore_key(key):
8686
return key.replace("-", "_")
8787

8888
key_path2b = list(map(_make_hyphen_key, key_path2))
89+
8990
# Here we want to split up each non-empty string in the list at
9091
# underscores and recombine the strings using chomp_empty_strings so
9192
# that leading, trailing and multiple _ will be preserved
@@ -1611,6 +1612,7 @@ def _add_annotation_like(
16111612
)
16121613
):
16131614
return self
1615+
16141616
# in case the user specified they wanted an axis to refer to the
16151617
# domain of that axis and not the data, append ' domain' to the
16161618
# computed axis accordingly

Diff for: plotly/data/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Built-in datasets for demonstration, educational and test purposes.
33
"""
4+
45
import os
56
from importlib import import_module
67

Diff for: plotly/express/_core.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,11 @@ def make_trace_spec(args, constructor, attrs, trace_patch):
985985

986986
def make_trendline_spec(args, constructor):
987987
trace_spec = TraceSpec(
988-
constructor=go.Scattergl
989-
if constructor == go.Scattergl # could be contour
990-
else go.Scatter,
988+
constructor=(
989+
go.Scattergl
990+
if constructor == go.Scattergl # could be contour
991+
else go.Scatter
992+
),
991993
attrs=["trendline"],
992994
trace_patch=dict(mode="lines"),
993995
marginal=None,
@@ -2456,9 +2458,11 @@ def get_groups_and_orders(args, grouper):
24562458
full_sorted_group_names = [
24572459
tuple(
24582460
[
2459-
""
2460-
if col == one_group
2461-
else sub_group_names[required_grouper.index(col)]
2461+
(
2462+
""
2463+
if col == one_group
2464+
else sub_group_names[required_grouper.index(col)]
2465+
)
24622466
for col in grouper
24632467
]
24642468
)

Diff for: plotly/express/data/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Built-in datasets for demonstration, educational and test purposes.
2-
"""
1+
"""Built-in datasets for demonstration, educational and test purposes."""
32

43
from plotly.data import *
54

Diff for: plotly/io/_templates.py

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def _merge_2_templates(self, template1, template2):
273273
templates = TemplatesConfig()
274274
del TemplatesConfig
275275

276+
276277
# Template utilities
277278
# ------------------
278279
def walk_push_to_template(fig_obj, template_obj, skip):

Diff for: plotly/matplotlylib/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
'tools' module or 'plotly' package.
1010
1111
"""
12+
1213
from plotly.matplotlylib.renderer import PlotlyRenderer
1314
from plotly.matplotlylib.mplexporter import Exporter

Diff for: plotly/matplotlylib/mplexporter/exporter.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
This submodule contains tools for crawling a matplotlib figure and exporting
55
relevant pieces to a renderer.
66
"""
7+
78
import warnings
89
import io
910
from . import utils

Diff for: plotly/matplotlylib/mplexporter/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Utility Routines for Working with Matplotlib Objects
33
====================================================
44
"""
5+
56
import itertools
67
import io
78
import base64

Diff for: plotly/matplotlylib/mpltools.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
A module for converting from mpl language to plotly language.
55
66
"""
7+
78
import math
89

910
import warnings
@@ -291,7 +292,7 @@ def convert_rgba_array(color_list):
291292
clean_color_list = list()
292293
for c in color_list:
293294
clean_color_list += [
294-
(dict(r=int(c[0] * 255), g=int(c[1] * 255), b=int(c[2] * 255), a=c[3]))
295+
dict(r=int(c[0] * 255), g=int(c[1] * 255), b=int(c[2] * 255), a=c[3])
295296
]
296297
plotly_colors = list()
297298
for rgba in clean_color_list:

Diff for: plotly/matplotlylib/renderer.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
with the matplotlylib package.
77
88
"""
9+
910
import warnings
1011

1112
import plotly.graph_objs as go

Diff for: plotly/offline/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
======
44
This module provides offline functionality.
55
"""
6+
67
from .offline import (
78
download_plotlyjs,
89
get_plotlyjs_version,

Diff for: plotly/offline/offline.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
""" Plotly Offline
2-
A module to use Plotly's graphing library with Python
3-
without connecting to a public or private plotly enterprise
4-
server.
1+
"""Plotly Offline
2+
A module to use Plotly's graphing library with Python
3+
without connecting to a public or private plotly enterprise
4+
server.
55
"""
6+
67
import os
78
import warnings
89
import pkgutil

Diff for: plotly/tools.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Functions that USERS will possibly want access to.
66
77
"""
8+
89
import json
910
import warnings
1011

@@ -571,6 +572,7 @@ def return_figure_from_figure_or_data(figure_or_data, validate_figure):
571572
DIAG_CHOICES = ["scatter", "histogram", "box"]
572573
VALID_COLORMAP_TYPES = ["cat", "seq"]
573574

575+
574576
# Deprecations
575577
class FigureFactory(object):
576578
@staticmethod

Diff for: plotly/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from _plotly_utils.utils import *
55
from _plotly_utils.data_utils import *
66

7+
78
# Pretty printing
89
def _list_repr_elided(v, threshold=200, edgeitems=3, indent=0, width=80):
910
"""

Diff for: pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ dependencies = [
4646

4747
[project.optional-dependencies]
4848
express = ["numpy"]
49+
dev = [
50+
"black==25.1.0"
51+
]
4952

5053
[tool.setuptools.packages.find]
5154
where = ["."]
@@ -61,7 +64,7 @@ plotly = [
6164

6265
[tool.black]
6366
line-length = 88
64-
target_version = ['py36', 'py37', 'py38', 'py39']
67+
target_version = ['py38', 'py39', 'py310', 'py311', 'py312']
6568
include = '\.pyi?$'
6669
exclude = '''
6770

Diff for: tests/test_core/test_graph_objs/test_annotations.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
A module intended for use with Nose.
66
77
"""
8+
89
from unittest import skip
910

1011
from plotly.exceptions import (

Diff for: tests/test_core/test_graph_objs/test_data.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
A module intended for use with Nose.
66
77
"""
8+
89
from unittest import skip
910

1011

Diff for: tests/test_core/test_graph_objs/test_error_bars.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
A module intended for use with Nose.
66
77
"""
8+
89
from plotly.graph_objs import ErrorX, ErrorY
910
from plotly.exceptions import PlotlyDictKeyError
1011

Diff for: tests/test_core/test_graph_objs/test_scatter.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
A module intended for use with Nose.
66
77
"""
8+
89
from plotly.graph_objs import Scatter
910
from plotly.exceptions import PlotlyError
1011

Diff for: tests/test_core/test_graph_objs/test_template.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def setUp(self):
416416
go.Bar(marker={"opacity": 0.7}),
417417
go.Bar(marker={"opacity": 0.4}),
418418
],
419-
"parcoords": [go.Parcoords(dimensiondefaults={"multiselect": True})]
419+
"parcoords": [go.Parcoords(dimensiondefaults={"multiselect": True})],
420420
# no 'scattergl'
421421
},
422422
)

Diff for: tests/test_core/test_offline/test_offline.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
test__offline
33
44
"""
5+
56
import json
67
import os
78
from unittest import TestCase

Diff for: tests/test_io/test_html.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import mock
1717
from mock import MagicMock
1818

19+
1920
# fixtures
2021
# --------
2122
@pytest.fixture

Diff for: tests/test_optional/test_offline/test_offline.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
test__offline
33
44
"""
5+
56
import re
67

78
from unittest import TestCase

Diff for: tests/test_optional/test_utils/test_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Module to test plotly.utils with optional dependencies.
33
44
"""
5+
56
import datetime
67
import math
78
import decimal

Diff for: tests/test_plotly_utils/validators/test_boolean_validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from _plotly_utils.basevalidators import BooleanValidator
33
from ...test_optional.test_utils.test_utils import np_nan
44

5+
56
# Boolean Validator
67
# =================
78
# ### Fixtures ###

Diff for: tests/test_plotly_utils/validators/test_colorscale_validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import inspect
66
import itertools
77

8+
89
# Fixtures
910
# --------
1011
@pytest.fixture()

Diff for: tests/test_plotly_utils/validators/test_dataarray_validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
import pandas as pd
55

6+
67
# Fixtures
78
# --------
89
@pytest.fixture()

Diff for: tests/test_plotly_utils/validators/test_enumerated_validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from _plotly_utils.basevalidators import EnumeratedValidator
55
from ...test_optional.test_utils.test_utils import np_inf
66

7+
78
# Fixtures
89
# --------
910
@pytest.fixture()

Diff for: tests/test_plotly_utils/validators/test_flaglist_validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
EXTRAS = ["none", "all", True, False, 3]
88
FLAGS = ["lines", "markers", "text"]
99

10+
1011
# Fixtures
1112
# --------
1213
@pytest.fixture(params=[None, EXTRAS])

Diff for: tests/test_plotly_utils/validators/test_integer_validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pandas as pd
88
from ...test_optional.test_utils.test_utils import np_nan, np_inf
99

10+
1011
# ### Fixtures ###
1112
@pytest.fixture()
1213
def validator():

Diff for: tests/test_plotly_utils/validators/test_number_validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pandas as pd
77
from ...test_optional.test_utils.test_utils import np_nan, np_inf
88

9+
910
# Fixtures
1011
# --------
1112
@pytest.fixture

0 commit comments

Comments
 (0)