Jason R. Coombs <jar...@jaraco.com> added the comment:

It seems that even on Python 3.9 or 3.10b2, the 
[DynamicRinohDistribution](https://github.com/brechtm/rinohtype/blob/e7f1c2c6066303d86cff4105be0829f512059be2/src/rinoh/resource.py#L132)
 would return `None` for the `name` property (despite the [attempt to return 
the empty 
string](https://github.com/brechtm/rinohtype/blob/e7f1c2c6066303d86cff4105be0829f512059be2/src/rinoh/resource.py#L135)).
 The Python object model doesn't allow overriding descriptor (@property) in a 
superclass with a static class property in the subclass.

I'm struggling to understand how the DynamicRinohDistribution works at all. I 
think I see. `importlib.metadata.Distribution`, while it declares a couple of 
abstract methods, doesn't actually declare itself an abstract base class, so 
someone can subclass it and get the degenerate behavior for the abstract 
methods. That's why a DynamicRinohDistribution.metadata gets `None` for 
`self.read_text` and then `email.message_from_string(None)` returns an empty 
`Message` object.

My instinct here is that the `Distribution.name` was always expected to return 
a string and the fact that it's returning `None` is a symptom of the subclass 
not implementing the abstract methods. To be sure, type annotations might have 
helped here (if the `name` property declared that the return type is `str`, 
then `None` would be an invalid return value).

The importlib distribution discovery mechanism was designed for other package 
distribution providers to make their distributions visible. It was not designed 
with the Rinoh use-case in mind (where a distribution already installed using 
the standard finders would present other "dynamic" distributions).

Given that Rinoh is using the distribution discovery mechanism in a way that it 
was not designed to support and is unlikely to be a widespread (or even 
repeated) use-case, I'm leaning toward a recommendation that the issue be fixed 
in Rinoh by defining a name property that returns text (and preferably 
something other than the empty string).

----------
priority: deferred blocker -> normal

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44459>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to