Skip to content
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

Entrypoint __iter__ implemementation breaks _asdict #337

Closed
RonnyPfannschmidt opened this issue Aug 11, 2021 · 4 comments · Fixed by #339
Closed

Entrypoint __iter__ implemementation breaks _asdict #337

RonnyPfannschmidt opened this issue Aug 11, 2021 · 4 comments · Fixed by #339
Assignees

Comments

@RonnyPfannschmidt
Copy link
Contributor

@RonnyPfannschmidt RonnyPfannschmidt commented Aug 11, 2021

def __iter__(self):
"""
Supply iter so one may construct dicts of EntryPoints by name.
"""
msg = (
"Construction of dict of EntryPoints is deprecated in "
"favor of EntryPoints."
)
warnings.warn(msg, DeprecationWarning)
return iter((self.name, self))

#debug from usage of the stdlib copy
(Pdb) v
EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm')
(Pdb) v._asdict()
{'name': '.git', 'value': EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm')}
(Pdb) type(v)
<class 'importlib.metadata.EntryPoint'>
(Pdb) v._fields
('name', 'value', 'group')
(Pdb) 

i was most surprised when my namedtuple debug printer turned into a endless recursion

@jaraco
Copy link
Member

@jaraco jaraco commented Aug 12, 2021

Also bpo-44893.

@jaraco jaraco self-assigned this Aug 13, 2021
jaraco added a commit that referenced this issue Aug 13, 2021
jaraco added a commit that referenced this issue Aug 13, 2021
jaraco added a commit that referenced this issue Aug 13, 2021
@jaraco
Copy link
Member

@jaraco jaraco commented Aug 13, 2021

In #338, I've drafted a fix, but before I merge the change, I'm pondering - does this project want to support the requested interface. I agree that it's reasonable to expect a namedtuple subclass to implement all the features of a namedtuple. This subclass, however, explicitly overrides the default expectation that __iter__ returns the values... and it was never the explicit intention that EntryPoint._asdict should work.

I originally made EntryPoint a subclass of a namedtuple as a shorthand to describe an object with three properties. I never intended it to be used as a tuple or namedtuple.

I've only learned in the past couple of years how dangerous it is to use a built-in type because it implements a subset of the features needed. In a formal API such as importlib.metadata exposes, it's important to be explicit about the minimum surface supported by the API... and using built-in types implicitly exposes a good deal of extraneous, sometimes unwanted functionality, violating the "preferably only one" obvious way.

Before embarking on supporting the requested behavior, I think it's worthwhile stepping back to ask - what is this functionality needed for?

Other approaches I'd like to consider:

  • Drop namedtuple as a base class and instead implement a "simple object with 3 properties" (possibly providing compatibility for behaviors that could be relied upon in the current implementation).
  • Drop support for non-working or unwanted namedtuple behaviors (through NotImplementedError or AttributeErrors).

Why should this project care about supporting _asdict()?

@RonnyPfannschmidt
Copy link
Contributor Author

@RonnyPfannschmidt RonnyPfannschmidt commented Aug 13, 2021

its a easy way to debug/trace details for namedtuples (where vars won't work)

in my own code i migrated to always use fields/getattr to wokr around the bug

i took note of the issue when it created a endless recursion in a debug helper

its not clear to me what most reasonable way to express a entrypoint would be,
its really unfortunate the iter "convenience" exists in the first place

imho it violates multiple python principles just to provide convenience,

@jaraco
Copy link
Member

@jaraco jaraco commented Aug 13, 2021

its really unfortunate the iter "convenience" exists in the first place

That I can agree, and that behavior is deprecated and slated for removal.

its a easy way to debug/trace details for namedtuples (where vars won't work)

in my own code i migrated to always use fields/getattr to wokr around the bug

i took note of the issue when it created a endless recursion in a debug helper

Thanks for clarifying. That doesn't strike me as a particularly compelling reason to keep this particular interface and more a reason to get rid of the qwirky __iter__ and excess namedtuple behaviors. If the debug helper is a one-off, a one-off workaround seems appropriate. If the debug helper is built into an ecosystem like pytest or Pycharm or similar, that to me is a much stronger case to find a solution.

In #339, I lay out the implementation I have in mind. Basically, eschew namedtuple and instead store keyword-only attributes on the object. The __iter__ hack is still there and still deprecated.

@jaraco jaraco closed this in #339 Aug 29, 2021
halstead pushed a commit to openembedded/openembedded-core that referenced this issue Oct 13, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
splitice pushed a commit to HalleyAssist/poky that referenced this issue Oct 13, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 01eb9d4384ae78b02780cea3b8690d99484b2602)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
splitice pushed a commit to HalleyAssist/poky that referenced this issue Oct 13, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 01eb9d4384ae78b02780cea3b8690d99484b2602)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
kraj pushed a commit to YoeDistro/poky that referenced this issue Oct 13, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 01eb9d4384ae78b02780cea3b8690d99484b2602)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
armcc pushed a commit to lgirdk/poky that referenced this issue Oct 13, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 01eb9d4384ae78b02780cea3b8690d99484b2602)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
splitice pushed a commit to HalleyAssist/poky that referenced this issue Oct 14, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 01eb9d4384ae78b02780cea3b8690d99484b2602)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
splitice pushed a commit to HalleyAssist/poky that referenced this issue Oct 14, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 01eb9d4384ae78b02780cea3b8690d99484b2602)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
splitice pushed a commit to HalleyAssist/poky that referenced this issue Oct 14, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 4272ca45d137b91ec368c94b3e0dbd7d56c616dd)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to openembedded/openembedded-core that referenced this issue Oct 14, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to openembedded/openembedded-core that referenced this issue Oct 14, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
seambot pushed a commit to hello-seam/poky that referenced this issue Oct 14, 2021
v4.8.1
  #348: Restored support for EntryPoint access by item, deprecating
        support in the process. Users are advised to use direct member
        access instead of item-based access:

    - ep[0] -> ep.name
    - ep[1] -> ep.value
    - ep[2] -> ep.group
    - ep[:] -> ep.name, ep.value, ep.group

v4.8.0
  #337: Rewrote EntryPoint as a simple class, still immutable and
        still with the attributes, but without any expectation for
        namedtuple functionality such as _asdict.

v4.7.1
  #344: Fixed regression in packages_distributions when neither
        top-level.txt nor a files manifest is present.

v4.7.0
  #330: In packages_distributions, now infer top-level names from
        .files() when a top-level.txt (Setuptools-specific metadata)
        is not present.

References:
  python/importlib_metadata#348
  python/importlib_metadata#337
  python/importlib_metadata#344
  python/importlib_metadata#330

(From OE-Core rev: 21d72ace8f9486bd1b478e28d53da64087d790fa)

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants