Opened 3 years ago

Closed 3 years ago

#25677 closed enhancement (fixed)

py3: normalize repr of bound methods in doctest results

Reported by: embray Owned by:
Priority: major Milestone: sage-8.3
Component: python3 Keywords: doctests
Cc: Merged in:
Authors: Erik Bray Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: 4c3e188 (Commits, GitHub, GitLab) Commit: 4c3e188c2b91108d615019fe869d9d9e66e2fe43
Dependencies: Stopgaps:

Status badges


Another fixer-upper for another very common (mostly) trivial doctest failure on Python 3.

On Python 2 bound methods are represented using the class name of the object the method was bound to, whereas on Python 3 they are represented with the fully-qualified name of the function that implements the method.

In the context of a doctest it's almost impossible to convert accurately from the latter to the former or vice-versa, so we simplify the reprs of bound methods to just the bare method name.

This is slightly regressive since it means one can't use the repr of a bound method to test whether some element is getting a method from the correct class (imporant sometimes in the cases of dynamic classes). However, such tests could be written could be written more explicitly to emphasize that they are testing such behavior, and will fail on Python 3 anyways.

Change History (4)

comment:1 Changed 3 years ago by chapoton

Is this ready for review ?

comment:2 Changed 3 years ago by embray

  • Status changed from new to needs_review

I think so. I wanted to make sure there weren't any other problems with it or that there weren't some corner cases it wasn't catching. The latter is still a possibility (hard to know until more of the tests are fixed) but this does fix a lot of tests as is.

comment:3 Changed 3 years ago by chapoton

  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

then let us move on

comment:4 Changed 3 years ago by vbraun

  • Branch changed from u/embray/python3/doctest/normalize-bound-method-repr to 4c3e188c2b91108d615019fe869d9d9e66e2fe43
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.