From f4023026878c8ab20695acc09a5e83ec9aff91ef Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Mon, 28 Nov 2022 09:11:37 +0200 Subject: [PATCH 1/4] Add support for Python 3.11 Closes #68. --- .github/workflows/build.yml | 1 + CHANGES.rst | 2 +- appveyor.yml | 1 + docs/generator-sample.txt | 2 +- docs/highlighting.txt | 2 +- docs/index.txt | 2 +- setup.py | 1 + tox.ini | 2 +- 8 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 676426f..003d669 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,6 +25,7 @@ jobs: - "3.8" - "3.9" - "3.10" + - "3.11" steps: - name: Install OS dependencies diff --git a/CHANGES.rst b/CHANGES.rst index 016ef82..6f6847d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,7 @@ Changes 3.5.1 (unreleased) ------------------ -- Add support for Python 3.9 and 3.10. +- Add support for Python 3.9, 3.10, and 3.11. - Drop support for Python 3.6. diff --git a/appveyor.yml b/appveyor.yml index f95698d..a739470 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,6 +9,7 @@ environment: - PYTHON: "C:\\Python38" - PYTHON: "C:\\Python39" - PYTHON: "C:\\Python310" + - PYTHON: "C:\\Python311" init: - "echo %PYTHON%" diff --git a/docs/generator-sample.txt b/docs/generator-sample.txt index dc10aa6..9a1011e 100644 --- a/docs/generator-sample.txt +++ b/docs/generator-sample.txt @@ -43,7 +43,7 @@ Or we can examine just one of the reference chains leading straight to a module. >>> objgraph.show_chain( ... objgraph.find_backref_chain(objgraph.by_type('Canary')[0], ... objgraph.is_proper_module), - ... filename='canary-chain.png') + ... filename='canary-chain.png') # doctest: +NODES_VARY Graph written to ....dot (11 nodes) Image generated as canary-chain.png diff --git a/docs/highlighting.txt b/docs/highlighting.txt index 95ba292..591e4a9 100644 --- a/docs/highlighting.txt +++ b/docs/highlighting.txt @@ -16,7 +16,7 @@ You can highlight some graph nodes. >>> objgraph.show_backrefs(a, max_depth=15, ... extra_ignore=[id(locals())], ... highlight=lambda x: isinstance(x, Node), - ... filename='highlight.png') + ... filename='highlight.png') # doctest: +NODES_VARY Graph written to ....dot (12 nodes) Image generated as highlight.png diff --git a/docs/index.txt b/docs/index.txt index e022ade..c7751dd 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -111,7 +111,7 @@ you've any examples where that isn't true, I'd love to hear about them ... objgraph.find_backref_chain( ... random.choice(objgraph.by_type('MyBigFatObject')), ... objgraph.is_proper_module), - ... filename='chain.png') + ... filename='chain.png') # doctest: +NODES_VARY Graph written to ...dot (13 nodes) Image generated as chain.png diff --git a/setup.py b/setup.py index 0a3fbb9..a841e10 100755 --- a/setup.py +++ b/setup.py @@ -81,6 +81,7 @@ def build_images(doctests=()): 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', ], keywords='object graph visualization graphviz garbage collection', py_modules=['objgraph'], diff --git a/tox.ini b/tox.ini index 55f6d65..f659d93 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py37, py38, py39, py310 +envlist = py27, py37, py38, py39, py310, py311 [testenv] deps = From 383667b2315efab6ff91f2fd5343305655a38a66 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Mon, 28 Nov 2022 09:22:08 +0200 Subject: [PATCH 2/4] Fix a test when using coverage on Python 3.11 I don't know why, but coverage.py creates a bunch of new FileDisposition objects here that jump to the top of the new objects list. I've seen +3 and +5. --- tests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 27a325a..d221f9a 100755 --- a/tests.py +++ b/tests.py @@ -378,14 +378,13 @@ def doctest_get_new_ids_prints(): >>> _ = objgraph.get_new_ids(limit=0) >>> _ = objgraph.get_new_ids(limit=0) - >>> a = [0, 1, 2] # noqa - >>> b = [3, 4, 5] # noqa + >>> a = [[] for n in range(10)] # noqa >>> _ = objgraph.get_new_ids(limit=1) ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ======================================================== Type Old_ids Current_ids New_ids Count_Deltas ======================================================== - list ... ... ... +2 + list ... ... ... +11 ======================================================== """ From c419edec21ea0d62520065d9fe0d6bc5bc19d74f Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Mon, 28 Nov 2022 09:50:05 +0200 Subject: [PATCH 3/4] Add more tests for 100% coverage under Python 3.11 Python 3.11 optimizes away creation of Python frame objects, so these branches are not getting executed as much as they used to be. https://docs.python.org/3/whatsnew/3.11.html#faster-runtime --- tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests.py b/tests.py index d221f9a..907846d 100755 --- a/tests.py +++ b/tests.py @@ -503,6 +503,17 @@ def a_method(self): self.assertEqual('a_method', objgraph._short_repr(MyClass.a_method)) + def test_short_repr_frame(self): + frame = sys._getframe() + # we're calling _short_repr() 6 lines down from here + lineno = frame.f_lineno + 6 + # Python >= 3.9 uses absolute filenames + expected = { + 'tests.py:%d' % lineno, + '%s:%d' % (os.path.abspath('tests.py'), lineno), + } + self.assertIn(objgraph._short_repr(frame), expected) + def test_gradient_empty(self): self.assertEqual((0.1, 0.2, 0.3), objgraph._gradient((0.1, 0.2, 0.3), @@ -513,6 +524,11 @@ def test_edge_label_frame_locals(self): self.assertEqual(' [label="f_locals",weight=10]', objgraph._edge_label(frame, frame.f_locals)) + def test_edge_label_frame_globals(self): + frame = sys._getframe() + self.assertEqual(' [label="f_globals",weight=10]', + objgraph._edge_label(frame, frame.f_globals)) + @skipIf(sys.version_info[0] > 2, "Python 3 has no unbound methods") def test_edge_label_unbound_method(self): class MyClass(object): From 719be2b43e0c7767340702567b08bd3253d34896 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Mon, 28 Nov 2022 09:51:17 +0200 Subject: [PATCH 4/4] Update copyright year --- objgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objgraph.py b/objgraph.py index 6c2c941..3600be5 100755 --- a/objgraph.py +++ b/objgraph.py @@ -3,7 +3,7 @@ You can find documentation online at https://mg.pov.lt/objgraph/ -Copyright (c) 2008-2017 Marius Gedminas and contributors +Copyright (c) 2008-2022 Marius Gedminas and contributors Released under the MIT licence. """