Skip to content

getTypeName: the name of an object's type without its module - #592

Merged
Paebbels merged 3 commits into
devfrom
claude/type-name
Oct 19, 2026
Merged

Paebbels merged 3 commits into
devfrom
claude/type-name

Conversation

@pytooling-claude

@pytooling-claude pytooling-claude Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

New Features

  • pyTooling.Common:
    • New function 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 with isinstance (no try/except on the common instance path), every other object the name of its class - for an instance the same as obj.__class__.__name__. It's the name, not the qualified name: a nested class Outer.Inner returns Inner.
    • It's the counterpart of 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 with getTypeName(...) instead of obj.__class__.__name__ (23 uses); the texts are unchanged.

Documentation

  • Common Helper Functions: new sections for getFullyQualifiedName and getTypeName, with examples.
  • doc/News.rst: entry under v10.0.0 › pyTooling.Common.

Unit Tests

  • New tests/unit/Common/TypeName.py: both functions for instances, classes, nested classes, functions and methods, and built-in types; getTypeName also for lambdas, bound methods, built-in functions and method descriptors.

Related Issues and Pull-Requests

…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>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 19, 2026 00:30
@pytooling-claude pytooling-claude Bot added Documentation Improvements or additions to documentation Enhancement New feature or request Unit Tests labels Oct 19, 2026
@codacy-production

codacy-production Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 minor

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Documentation 2 minor

View in Codacy

🟢 Metrics 15 complexity · 0 duplication

Metric Results
Complexity 15
Duplication 0

View in Codacy

🟢 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

View coverage diff in Codacy

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>
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2673 1 2672 18
View the top 1 failed test(s) by shortest run time
TypeName.TypeName::test_BuiltinMethodDescriptor
Stack Traces | 0.016s run time
No failure message available

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment thread pyTooling/Common/__init__.py Resolved
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>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels October 19, 2026 10:08
@Paebbels
Paebbels merged commit 3dfc28a into dev Oct 19, 2026
52 of 62 checks passed
@Paebbels
Paebbels deleted the claude/type-name branch October 19, 2026 14:31
This was referenced Oct 20, 2026
@pytooling-claude pytooling-claude Bot added this to the v10.0 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Enhancement New feature or request Unit Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants