Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Update doc string for python 3.12 #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

dschwoerer
Copy link
Contributor

Resolves test failure with python3.12:

Failed build and log

Fixed build and log

@tomschr
Copy link
Member

tomschr commented Jul 7, 2023

Hi @dschwoerer, thanks for your report.

This is a bit confusing. I've tried a Python shell session:

$ python3.12 --version
Python 3.12.0b2 (main, Jul  7 2023, 07:49:42) [GCC 7.5.0] on linux
$ python3.12
>>> from collections import OrderedDict

>>> OrderedDict({'major': 3, 'minor': 4, 'patch': 5, 'prerelease': None, 'build': None})
OrderedDict({'major': 3, 'minor': 4, 'patch': 5, 'prerelease': None, 'build': None})

>>> OrderedDict([('major', 3), ('minor', 4), ('patch', 5), ('prerelease', None), ('build', None)])
OrderedDict({'major': 3, 'minor': 4, 'patch': 5, 'prerelease': None, 'build': None})

Both syntax variants are possible with OrderedDict. I'm just not sure why it doesn't work in the doctest. 🤔

Any idea?

@tomschr
Copy link
Member

tomschr commented Jul 7, 2023

After I've fixed the long line issue, it seems the GitHub Actions are not so happy with your change. 😉

Your "fix" may work for Python 3.12, but breaks the other versions. I'm sorry, but I can't accept this fix as it is.

We need to investigate further.

@tomschr
Copy link
Member

tomschr commented Jul 7, 2023

Ok, I digged deeper and there is a change between 3.12 and the other Python versions. It's in the __repr__ method.

In Python 3.12 you have this code (see source):

@_recursive_repr()
def __repr__(self):
  'od.__repr__() <==> repr(od)'
  if not self:
      return '%s()' % (self.__class__.__name__,)
  return '%s(%r)' % (self.__class__.__name__, dict(self.items()))

whereas in Python 3.11 you have this (see source):

@_recursive_repr()
def __repr__(self):
  'od.__repr__() <==> repr(od)'
  if not self:
      return '%s()' % (self.__class__.__name__,)
  return '%s(%r)' % (self.__class__.__name__, list(self.items()))

The last line is the culprit.

Seems we need to change the doctest somehow which does not relate to OrderedDict. I have something like this in mind:

>>> list(OrderedDict({'major': 3, 'minor': 4, 'patch': 5, 'prerelease': None, 'build': None}).items())
[('major', 3), ('minor', 4), ('patch', 5), ('prerelease', None), ('build', None)]

Do you have a better idea?

@dschwoerer
Copy link
Contributor Author

I do not know doc tests, so I only managed to get the fix for 3.12

As you claim to support 3.12 on pypi, I thought you may be interested :-)

It may be best to always return a dict?
They are sorted since python3.6. I don't think you need OrderedDicts, the benefit OrderedDicts provide are not likely useful.

Do you want me to change it to return dict? That way the doc test would not need to be conditionalised ...

Of course, using to list or something could also work ...

The OrderedDict.__repr__ method was changed in Python 3.12
to output a different string than before (see python-semver#418 for details).

The respective doctests which show the output was marked as
"skipped" with the above directive. We keep the test for documentation
purpuses.

In the test tests/test_semver.py::test_should_versioninfo_to_dict
we test the keys and values separately.
@tomschr
Copy link
Member

tomschr commented Jul 7, 2023

Thanks for your answer! I think I found a solution to this problem which I committed to 686ce67.

It may be best to always return a dict?

That could indeed an option. I haven't thought about that. 😄 The OrderedDict was introduced due to Python 3.6 as the dict wasn't ordered. As we don't support this version anymore, we might use a simple dict.

Do you want me to change it to return dict? That way the doc test would not need to be conditionalised ...

Yes, please! That would be great! 👍 You need to adapt these files:

  • docs/usage/convert-version-into-different-types.rst
  • docs/usage/create-a-version.rst
  • src/semver/version.py

Look for my last commit to see which lines.

@tomschr
Copy link
Member

tomschr commented Jul 12, 2023

This PR can be closed as #419 is merged now. Thanks!

@tomschr tomschr closed this Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.