Repository navigation
getTypeName: the name of an object's type without its module - #592
Conversation
…s module. Requested in pyVHDLModel #203: exception messages name a class by its name (obj.__class__.__name__, 24 uses in pyTooling alone), while the note reporting a wrong type uses getFullyQualifiedName. getTypeName makes the first half one call too: a class or a function returns its own name, every other object the name of its class (__name__, not __qualname__, so it equals obj.__class__.__name__ for instances). Documentation: sections for getFullyQualifiedName and getTypeName on the Common helper functions page; seealso both ways; News entry. Tests for both functions. Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Documentation | 2 minor |
🟢 Metrics 15 complexity · 0 duplication
Metric Results Complexity 15 Duplication 0
🟢 Coverage 78.38% diff coverage · +0.01% coverage variation
Metric Results Coverage variation ✅ +0.01% coverage variation (-1.00%) Diff coverage ✅ 78.38% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (bee2d7d) 15301 13846 90.49% Head commit (2786661) 15310 (+9) 13855 (+9) 90.50% (+0.01%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#592) 37 29 78.38% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
…name__'. 23 uses in Attributes, CLIAbstraction, Configuration, MetaClasses, Testing, Tracing and Versioning; the message texts are unchanged. A commented-out debug print in MetaClasses keeps its spelling. The ExtendedTypeError raise in __getstate__ is wrapped to stay within 120 columns. Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Review: the common case - an instance - raised and caught an AttributeError each call. An isinstance check against the types carrying their own name (classes, functions, methods, incl. built-in ones and method descriptors) is faster for instances and keeps every function-like object returning its own name (timeit, best of 7, 1M calls): instance: try/except 457 ns -> isinstance 168 ns (3.15); 307 ns -> 111 ns (3.13) class: try/except 34 ns -> isinstance 46 ns (3.15); 30 ns -> 39 ns (3.13) The tuple is a module-level private constant: built per call it would cost 8 global lookups each time. A module object now returns 'module' (its class name), no longer its own name. Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
c0f2bdd to
2786661
Compare
New Features
pyTooling.Common:getTypeName(obj): the name of an object's type without its module. A class, a function or a method (built-in ones and method descriptors included) returns its own name, checked withisinstance(notry/excepton the common instance path), every other object the name of its class - for an instance the same asobj.__class__.__name__. It's the name, not the qualified name: a nested classOuter.InnerreturnsInner.getFullyQualifiedName(obj)for exception messages: the message names a class by its name, a note reporting a wrong type uses the fully qualified name. Both doc-strings cross-reference each other.Changes
pyTooling.Attributes,pyTooling.CLIAbstraction,pyTooling.Configuration,pyTooling.MetaClasses,pyTooling.Testing,pyTooling.Tracing,pyTooling.Versioning: messages and notes name a class withgetTypeName(...)instead ofobj.__class__.__name__(23 uses); the texts are unchanged.Documentation
getFullyQualifiedNameandgetTypeName, with examples.doc/News.rst: entry under v10.0.0 ›pyTooling.Common.Unit Tests
tests/unit/Common/TypeName.py: both functions for instances, classes, nested classes, functions and methods, and built-in types;getTypeNamealso for lambdas, bound methods, built-in functions and method descriptors.Related Issues and Pull-Requests
>= 10.0.