question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test failures in Python 3.11.0b3

See original GitHub issue

Environment details

  • Programming language: Python
  • OS: Fedora 37 (rawhide)
  • Language runtime version: Python 3.11.0b3
  • Package version: v1.20.6

Steps to reproduce

  1. Run pytest in Python 3.11.0b3

The first failure appears in test_total_ordering_w_other_enum_type:

____________________ test_total_ordering_w_other_enum_type _____________________
    def test_total_ordering_w_other_enum_type():
        to_compare = enums_test.OneEnum.SOME_VALUE
    
        for item in enums_test.OtherEnum:
            assert not to_compare == item
>           assert to_compare.SOME_VALUE != item
tests/test_enum_total_ordering.py:52: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <enum.property object at 0x3ffa350e550>
instance = <OneEnum.SOME_VALUE: 1>, ownerclass = <enum 'OneEnum'>
    def __get__(self, instance, ownerclass=None):
        if instance is None:
            try:
                return ownerclass._member_map_[self.name]
            except KeyError:
                raise AttributeError(
                        '%r has no attribute %r' % (ownerclass, self.name)
                        )
        else:
            if self.fget is None:
>               raise AttributeError(
                        '%r member has no attribute %r' % (ownerclass, self.name)
                        )
E               AttributeError: <enum 'OneEnum'> member has no attribute 'SOME_VALUE'
/usr/lib64/python3.11/enum.py:198: AttributeError

The second is in test_enum_alias_good:

_____________________________ test_enum_alias_good _____________________________
    def test_enum_alias_good():
        # Have to split good and bad enum alias into two tests so that the generated
        # file descriptor is properly created.
        # For the python runtime, aliases are allowed by default, but we want to
        # make sure that the options don't cause problems.
        # For the cpp runtime, we need to verify that we can in fact define aliases.
>       class GoodMessage(proto.Message):
tests/test_fields_enum.py:386: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_fields_enum.py:387: in GoodMessage
    class GoodEnum(proto.Enum):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
mcls = <class 'proto.enums.ProtoEnumMeta'>, name = 'GoodEnum'
bases = (<enum 'Enum'>,)
attrs = {'_generate_next_value_': <function Enum._generate_next_value_ at 0x3ffa5a8f560>, '__module__': 'test_fields_enum', '__qualname__': 'test_enum_alias_good.<locals>.GoodMessage.GoodEnum', 'UNKNOWN': 0, 'DEFAULT': 0}
    def __new__(mcls, name, bases, attrs):
        # Do not do any special behavior for `proto.Enum` itself.
        if bases[0] == enum.IntEnum:
            return super().__new__(mcls, name, bases, attrs)
    
        # Get the essential information about the proto package, and where
        # this component belongs within the file.
        package, marshal = _package_info.compile(name, attrs)
    
        # Determine the local path of this proto component within the file.
        local_path = tuple(attrs.get("__qualname__", name).split("."))
    
        # Sanity check: We get the wrong full name if a class is declared
        # inside a function local scope; correct this.
        if "<locals>" in local_path:
            ix = local_path.index("<locals>")
            local_path = local_path[: ix - 1] + local_path[ix + 1 :]
    
        # Determine the full name in protocol buffers.
        full_name = ".".join((package,) + local_path).lstrip(".")
        filename = _file_info._FileInfo.proto_file_name(
            attrs.get("__module__", name.lower())
        )
    
        # Retrieve any enum options.
        # We expect something that looks like an EnumOptions message,
        # either an actual instance or a dict-like representation.
        pb_options = "_pb_options"
        opts = attrs.pop(pb_options, {})
        # This is the only portable way to remove the _pb_options name
        # from the enum attrs.
        # In 3.7 onwards, we can define an _ignore_ attribute and do some
        # mucking around with that.
        if pb_options in attrs._member_names:
>           idx = attrs._member_names.index(pb_options)
E           AttributeError: 'dict' object has no attribute 'index'
../../BUILDROOT/python-proto-plus-1.20.6-1.fc37.noarch/usr/lib/python3.11/site-packages/proto/enums.py:61: AttributeError

For the second one, one of my coworkers found that _member_names is now a dict from a recent PR.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
hroncokcommented, Jun 16, 2022

AttributeError: <enum ‘OneEnum’> member has no attribute ‘SOME_VALUE’

This is because enum members do no longer have attributes with all other enum members.

Python 3.10:

>>> from enum import Enum
>>> class Color(Enum):
...     RED = 1
...     GREEN = 2
...     BLUE = 3
... 
>>> Color.RED
<Color.RED: 1>
>>> Color.RED.RED
<Color.RED: 1>
>>> Color.RED.RED.RED
<Color.RED: 1>
>>> Color.RED.RED.RED.BLUE
<Color.BLUE: 3>
>>> Color.RED.RED.RED.BLUE.BLUE.GREEN.RED
<Color.RED: 1>

Python 3.11:

>>> from enum import Enum
>>> class Color(Enum):
...     RED = 1
...     GREEN = 2
...     BLUE = 3
... 
>>> Color.RED
<Color.RED: 1>
>>> Color.RED.RED
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.11/enum.py", line 198, in __get__
    raise AttributeError(
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: <enum 'Color'> member has no attribute 'RED'

That assert there IMHO makes no sense because to_compare.SOME_VALUE is to_compare and the same assertion passed in the above line.

1reaction
partheacommented, Jun 28, 2022

@hroncok , The patch looks great. Please could you open a PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expedited release of Python3.11.0b3 - Committers
Hi everyone,. Due to a known incompatibility with pytest and the previous beta release (Python 3.11.0b2) and after
Read more >
What's New In Python 3.11 — Python 3.11.1 documentation
This article explains the new features in Python 3.11, compared to 3.10. ... These enhanced errors can also be helpful when dealing with...
Read more >
Changelog — Python 3.11.1 documentation
Instead of using such text, it will warn and act as if a match was not found (or for test commands, as if...
Read more >
Is this change in debug ranges between 3.11b3 and 3.11b4 ...
A few of them center around the testsuite failing on 3.11.0b4 ... I tried reading the differences between 3.11.0b3 and 3.11.0b4 but I...
Read more >
Python Release Python 3.11.0b2
We strongly encourage maintainers of third-party Python projects to test with 3.11 during the beta phase and report issues found to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found