Skip to content

Mark base node classes as ABCs #11676

Closed
@bluetech

Description

@bluetech

The Node class hierarchy has some classes which are only meant to be used as base classes, never instantiated directly. These are Node, Collector, Item, File, FSCollector, PyCollector.

I propose we mark them as abstract i.e. inherit from abc.ABC. Reasons:

  • Trying to instantiate fails quickly at runtime
  • Type checkers issue an error if trying to instantiate
  • The docs will show abstractmethod on the abstract methods that need to be implemented (collect or runtest), and show inheritance from ABC making it clear it's a base class

It seems somewhat hard to deprecate, and it will only cause errors when the code is already very wrong. So I propose to do it in pytest 8.0 without deprecation.

Metadata

Metadata

Assignees

Labels

topic: collectionrelated to the collection phasetopic: typingtype-annotation issuetype: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelogtype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions