Skip to content

Conversation

@asottile
Copy link
Member

@asottile asottile commented Oct 2, 2018

Resolves #4066

return Source(strsrc, **kwargs)


def deindent(lines, offset=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove offset: I've added assert offset is None to the beginning of Source.deindent and the entire suite executed without triggering the assert. Can you check please if that's the case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is indeed the case, are we ok breaking this api?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dedent is in _pytest._code.source, so I don't believe it will break any code. @RonnyPfannschmidt's concern was with the Source object, which is exposed by testdir, but here it is not the case.

@RonnyPfannschmidt please correct me if I'm wrong. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, I was also going to remove offset=None in Source.deindent as well, that's slightly closer to a break but still nobody should be calling it 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i all for removing that api

@coveralls
Copy link

coveralls commented Oct 3, 2018

Coverage Status

Coverage increased (+0.02%) to 93.805% when pulling e5ab62b on asottile:deindent_4066 into 20f93ae on pytest-dev:master.

@codecov
Copy link

codecov bot commented Oct 3, 2018

Codecov Report

Merging #4069 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4069      +/-   ##
==========================================
+ Coverage   94.49%   94.53%   +0.04%     
==========================================
  Files         109      109              
  Lines       23837    23802      -35     
  Branches     2361     2348      -13     
==========================================
- Hits        22524    22502      -22     
+ Misses       1002      996       -6     
+ Partials      311      304       -7
Flag Coverage Δ
#doctesting 29.25% <100%> (+0.77%) ⬆️
#linux 94.39% <100%> (+0.04%) ⬆️
#nobyte 0% <ø> (ø) ⬆️
#numpy 28.15% <100%> (+0.06%) ⬆️
#pexpect 0% <ø> (ø) ⬆️
#py27 92.66% <100%> (+0.04%) ⬆️
#py34 92.11% <100%> (+0.03%) ⬆️
#py35 92.12% <100%> (+0.03%) ⬆️
#py36 92.7% <100%> (+0.04%) ⬆️
#py37 92.33% <100%> (+0.03%) ⬆️
#trial 31.18% <100%> (+0.21%) ⬆️
#windows 93.84% <100%> (+0.59%) ⬆️
#xdist 18.59% <50%> (+0.12%) ⬆️
Impacted Files Coverage Δ
src/_pytest/_code/source.py 90.56% <100%> (-0.09%) ⬇️
testing/code/test_source.py 96.79% <100%> (-0.01%) ⬇️
src/_pytest/terminal.py 91.62% <0%> (+1.74%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 20f93ae...e5ab62b. Read the comment docs.

def __init__(self, *parts, **kwargs):
self.lines = lines = []
de = kwargs.get("deindent", True)
rstrip = kwargs.get("rstrip", True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe this is a breaking api change - what where our guarantees on those internals

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an api break, the parameter is ignored (nothing is validated about **kwargs)

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on initial review of the necessary test changes its broken worse now


lines = deindent(inspect.getsource(f).splitlines())
assert lines == ["def f():", ' c = """while True:', " pass", '"""']
assert lines == [" def f():", ' c = """while True:', " pass", '"""']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks pretty much broken now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same ad the test above, but in list form, I'm pretty sure this is more correct than before (before it introduced an indentation error)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see what you mean, please make it a indented block with disabled black formatting and a comment that the indent of the last """ is the relative ancor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel I could also delete this test since the above one covers the same behavior and is more expressive 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, true actually

@RonnyPfannschmidt RonnyPfannschmidt dismissed their stale review October 3, 2018 07:18

my missunderstanding was resolved

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 👍 😄

@asottile asottile merged commit b098292 into pytest-dev:master Oct 3, 2018
@asottile asottile deleted the deindent_4066 branch October 3, 2018 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants